{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>

<style type="text/css">
.frm_input_box{width: 225px!important}
</style>
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">任务包列表</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20"/>
        </div>
        <span class="frm_input_box search append">
            <input type="text" id="js_keyword" placeholder="请输入手机号" value="" class="frm_input" />
        </span>
        <span class="frm_input_box search append">
            <input type="text" id="js_username" placeholder="请输入用户名" value="" class="frm_input" />
        </span>
        <span class="frm_input_box search append">
            <input type="text" id="js_order_sn" placeholder="请输入编号" value="" class="frm_input" />
        </span>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="equip_name" placeholder="请输入任务包名称" value="" class="frm_input" />
        </span>
        <span>
            <select name="status" id="status" class="form-control" style="width:120px">
                <option value="">筛选订单状态</option>
                <option value="0">进行中</option>
                <option value="1">已结束</option>
            </select>
        </span>
        <span class="right">
             <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加孵化任务包</button>
             <button type="button" id="js_addBtn2" class="btn btn-primary"><i class="icon wb-plus"></i> 添加DC任务包</button>
             <button type="button" id="js_addBtn3" class="btn btn-primary"><i class="icon wb-plus"></i> 添加KOF任务包</button>
            <!-- <button type="button" id="add_days" class="btn btn-primary"><i class="icon wb-plus"></i> 补偿天数</button> -->
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:100,align:'center'">用户名</th>
        <th data-options="field:'phone',width:100,align:'center'">手机号</th>
        <th data-options="field:'order_sn',width:200,align:'center'">编号</th>
        <th data-options="field:'equip_name',width:100,align:'center'">任务包名称</th>
        <th data-options="field:'amount',width:100,align:'center'">购买金额</th>
        <th data-options="field:'total_amount',width:100,align:'center'">总额度</th>
        <th data-options="field:'total_release',width:100,align:'center'">已释放额度</th>
        <th data-options="field:'day_release',width:100,align:'center'">今日产出额度</th>
        <th data-options="field:'status',width:80,align:'center',formatter:formatStatus">状态</th>
        </thead>
        <thead>
            <tr>
                <th data-options="field:'days_release',width:100,align:'center'">每日日释放</th>
                <th data-options="field:'create_time',width:160,align:'center'">添加时间</th>
<!--                <th data-options="field:'update_time',width:160,align:'center'">修改时间</th>-->
                <th data-options="field:'end_time',width:160,align:'center'">到期时间</th>
                 <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">
    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });
    //状态
    function formatStatus(value,row,index){
        switch (value){
            case 0 :
                var text = '<span style="color:green">进行中</span>';
                break;
            default:
                var text = '<span style="color:red">已结束</span>';
        }
        return text;
    }

    function formatImg(value) {
        html = '';
        if(value!=null){
            html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
        }
        return html;
        
    }
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        // html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        html += '<button type="button" onclick="endOrder(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>结束订单</button>';
        html += '</span>';
        return html;
    }

    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_equip_1');
        openBarWin('添加孵化任务包',1000, 500, url, function () {
            reload();
        });
    });

    $("#js_addBtn2").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_equip_2');
        openBarWin('添加DC任务包',1000, 500, url, function () {
            reload();
        });
    });

    $("#js_addBtn3").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_equip_3');
        openBarWin('添加KOF任务包',1000, 500, url, function () {
            reload();
        });
    });

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

    //解冻账号
    function endOrder(id) {
        confirm("确认要结束此订单吗？", function () {
            var url = getURL('endOrder');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑装备', 600, 500, url, function () {
            reload();
        }, ['保存', '取消']);
    }

    function del(id) {
        confirm("确认要删除此装备吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    // $("#js_addBtn").click(function () {
    //     if ($(this).hasClass("disabled")) {
    //         return;
    //     }
    //     var url = getURL('edit');
    //     openBarWin('添加装备', 1000, 600, url, function () {
    //         reload();
    //     });
    // });
     $("#add_days").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_days');
        openBarWin('补偿天数', 400, 300, url, function () {
            reload();
        }, ['保存', '取消']);
    });

    $("#js_search").click(function () {
        reload();
    });

    $("#status").change(function () {
        reload();
    });

    function reload() {
        var keyword = $("#js_keyword").val();
        var js_username = $("#js_username").val();
        var js_order_sn = $("#js_order_sn").val();
        var equip_name = $("#equip_name").val();
        var status = $("#status").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            equip_name: equip_name,
            js_username: js_username,
            js_order_sn: js_order_sn,
            status: status,
            startDate: startDate,
            endDate: endDate
        });
    }
</script>
{/block}